﻿var msgBox = null;
var tarUrl = "../Action/getBackPwd.ashx";
$(function () {
    $("#fSUpdatePwd").hide();
    //1.创建消息框
    msgBox = new MsgBox({ imghref: "../images/" });
    $("input[id=btnNext]").click(getNext);
    $("input[id=btnPrv]").click(getPrv);
    $("input[id=btnNext1]").click(getNext1);
    Edit();
});


function Edit()
{
    $.post(tarUrl, { type: "mibao" }, function (jsObj) {
        if (jsObj.statu == "ok") {
            var _data = [];
            for (var i = 0; i < jsObj.data.GetMibaoList.length; i++)
            {
                for (var j = 0; j < jsObj.data.GetMbQuestionList.length; j++)
                {
                    if (jsObj.data.GetMbQuestionList[j].Id == jsObj.data.GetMibaoList[i].questionId) 
                    {
                        _data.push({ Id: jsObj.data.GetMbQuestionList[j].Id, Name:jsObj.data.GetMbQuestionList[j].QuestionM});
                    }
                }
            }
            //var str1 = "<option value='" + _data[0].Id + "'>" + _data[0].Name + "</option>";
            //var str2 = "<option value='" + _data[1].Id + "'>" + _data[1].Name + "</option>";
            //var str3 = "<option value='" + _data[2].Id + "'>" + _data[2].Name + "</option>";
            $("#MiBao1").val(_data[0].Id);
            $("#MiBao1").attr("disabled", "disabled");
            $("#MiBao2").val(_data[1].Id);
            $("#MiBao2").attr("disabled", "disabled");
            $("#MiBao3").val(_data[2].Id);
            $("#MiBao3").attr("disabled", "disabled");
            msgBox.showMsgOk(jsObj.msg);
        } else
        {
            msgBox.showMsgOk(jsObj.msg);
        }
    }, "json")
}


function getPrv()
{
    $("#fSUpdatePwd").hide();
    $("#fSInfoMobao").show();
}

function getNext1() {
    var pwd1 = $("#Txtpwd").val().trim();
    var pwd2 = $("#TxtCpwd").val().trim();
    if (pwd1 != pwd2)
    {
        msgBox.showMsgErr("两次填写密码不一致！");
        return;
    }
    $.post(tarUrl, { type: "password", pwd1: pwd1 }, function (jsObj) {
        if (jsObj.statu == "ok")
        {
            msgBox.showMsgOk(jsObj.msg);
            window.location =jsObj.data;
        }
    }, "json")
}
function getNext()
{
    $.post(tarUrl, { type: "mibao" }, function (jsObj) {
        if (jsObj.statu == "ok") {
           var question1 = $("#Question1").val();
           var question2 = $("#Question2").val();
           var question3 = $("#Question3").val();
           if (jsObj.data.GetMibaoList[0].Name.trim() != question1.trim())
           {
               msgBox.showMsgErr("第一个答案与数据不匹配！");
               return;
           }else if (jsObj.data.GetMibaoList[1].Name.trim() != question2.trim()) {
               msgBox.showMsgErr("第二个答案与数据不匹配！");
               return;
           }else if (jsObj.data.GetMibaoList[2].Name.trim() != question3.trim()) {
               msgBox.showMsgErr("第三个答案与数据不匹配！");
               return;
           }          
           $("#fSInfoMobao").hide();
           $("#fSUpdatePwd").show();
        } else {
            msgBox.showMsgOk(jsObj.msg);
        }
    }, "json")
}
function processData(jsObj, okFunc, errFunc) {
    //根据返回的 数据 状态 执行相应的操作
    switch (jsObj.statu) {
        case "ok"://如果ok则执行 ok回调函数
            if (okFunc) okFunc();
            msgBox.showMsgOk(jsObj.msg);
            break;
        case "err"://如果err的话，则 执行 err 回调函数
            if (errFunc) errFunc();
            msgBox.showMsgErr(jsObj.msg);
            break;
        case "np"://没有权限，则直接跳转到指定页面
            msgBox.showMsgErr(jsObj.msg, function () {
                window.location = jsObj.nextUrl;
            });
            break;
    }
}